package com.tedu.goods.controller;

import com.tedu.common.response.JsonResult;
import com.tedu.goods.pojo.dto.GoodsParam;
import com.tedu.goods.pojo.dto.GoodsQuery;
import com.tedu.goods.pojo.vo.GoodsVO;
import com.tedu.goods.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.Query;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/goods")
public class GoodsController {
    @Autowired GoodsService goodsService;

    @GetMapping("select")
    public JsonResult selectGoods(GoodsQuery goodsQuery){
        log.debug("查询商品列表,参数:{}",goodsQuery);
        List<GoodsVO> list = goodsService.selectGoods(goodsQuery);
        log.debug("查询商品列表,结果:{}",list);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult saveGoods(GoodsParam goodsSaveParam){
        log.debug("保存商品信息,参数:{}",goodsSaveParam);
        goodsService.saveGoods(goodsSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("/delete/{id}")
    public JsonResult deleteGoods(@PathVariable Long id){
        log.debug("删除车辆,参数:={}",id);
        goodsService.deleteGoods(id);
        return JsonResult.ok();
    }
    @PostMapping("/update/status/{goodsId}/{status}")
    public JsonResult updateStatus(
            @PathVariable Integer goodsId,@PathVariable String status){
        log.debug("修改商品状态:参数={},{}",goodsId,status);
        goodsService.updateStatus(goodsId,status);
        return JsonResult.ok();
    }

}
